const express = require('express');
const fs = require('fs');
const app = express();
const data = fs.readFileSync('piaofang.json', 'utf-8');
newData = JSON.parse(data);
app.get('/filmpiaofang/:filmname',(req,res) => {
    for(let index = 0 ;index < newData.list.length;index++){
        const element = newData.list[index];
        if(element.movieInfo.movieName === req.params.filmname){
            res.send(`${req.params.filmname}的上映时间是:${element.movieInfo.releaseInfo}`)
        }
    }
})
app.get('/filmchangci/:filmname',(req,res) => {
    for(let index = 0 ;index < newData.list.length;index++){
        const element = newData.list[index];
        if(element.movieInfo.movieName === req.params.filmname){
            res.send(`${req.params.filmname}的上映场次是:${element.showCount}`)
            }
        }
    }
);
app.get('/filmtime/:filmname',(req,res) => {
    for(let index = 0 ;index < newData.list.length;index++){
        const element = newData.list[index];
        if(element.movieInfo.movieName === req.params.filmname){
            res.send(`${req.params.filmname}的上座率是:${element.avgSeatView}`)
            }
        }
    }
);

// const xiaoshuoData = fs.readFileSync('xiaoshuo.json', 'utf-8');
// const xiaoshuoJson = JSON.parse(xiaoshuoData);

// app.get('/xiaoshuo/author/:bookname',(req,res) => {
//     for(let index = 0 ;index < xiaoshuoJson.result.bookList.length;index++){
//         const element = xiaoshuoJson.result.bookList[index];
//         if(element.bookName === req.params.bookname){
//             res.send(`${req.params.bookname}的作者是:${element.authorName}`)
//         }
//     }
// })
// app.get('/xiaoshuo/updatetime/:bookname',(req,res) => {
//     for(let index = 0 ;index < xiaoshuoJson.result.bookList.length;index++){
//         const element = xiaoshuoJson.result.bookList[index];
//         if(element.bookName === req.params.bookname){
//             res.send(`${req.params.bookname}的更新时间是:${element.updateTime}`)
//         }
//     }
// })
// app.get('/xiaoshuo/type/:bookname',(req,res) => {
//     for(let index = 0 ;index < xiaoshuoJson.result.bookList.length;index++){
//         const element = xiaoshuoJson.result.bookList[index];
//         if(element.bookName === req.params.bookname){
//             res.send(`${req.params.bookname}的小说类型是:${element.cateShortName}`)
//         }
//     }
// })
app.listen(3000,() => console.log('server is running'))